package com.hxzy.common.web.resp;


import com.hxzy.common.enums.AckCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * 消息API统一响应模型类
 */
@Getter
@Setter
@ApiModel(value = "统一响应模型")
public class R<T> {
    /**
     * 响应的自定义编码
     */
    @ApiModelProperty(value = "响应的编码")
    private Integer code;

    /**
     * 响应的消息
     */
    @ApiModelProperty(value = "响应的消息")
    private String msg;

    /**
     * 响应的数据
     */
    @ApiModelProperty(value = "响应的数据")
    private T data;


    public synchronized static <T> R<T> build(AckCode statusEnum) {
        return build(statusEnum, null);
    }

    public synchronized static <T> R<T> build(AckCode ackCode, T data) {
        R<T> res = new R<>();
        res.setCode(ackCode.getCode());
        res.setMsg(ackCode.getMsg());
        res.setData(data);
        return res;
    }

    public synchronized static <T> R<T> build(AckCode ackCode, T data, String msg) {
        R<T> res = new R<>();
        res.setCode(ackCode.getCode());
        res.setMsg(msg);
        res.setData(data);
        return res;
    }

    public synchronized static <T> R<T> ok() {
        return build(AckCode.SUCCESS, null);
    }

    public synchronized static <T> R<T> okHasData(T data) {
        return build(AckCode.SUCCESS, data);
    }


}
